home *** CD-ROM | disk | FTP | other *** search
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <winb.h>
- #include <te.h>
- #include <fntb.h>
- #include <gui.h>
- #include <egb.h>
- #include <guidbg.h>
- #include "win.h"
-
- void main()
- {
- MMICTRL ctrl;
- extern int APL_init();
-
- if (MMI_CallMessage(MMI_GetApliId(), GM_QUERYID, QM_KIND, 1) > NOERR)
- return;
-
- ctrl.displayPage = SCREENAVAILABLE;
- ctrl.mode = SCREENAVAILABLE;
- ctrl.page0 = SCREENIGNORE;
- ctrl.page1 = SCREENIGNORE;
- ctrl.size = 0;
- ctrl.ptr = NULL;
- ctrl.asize = 0;
- ctrl.aptr = NULL;
- ctrl.white = 15;
- ctrl.black = 8;
- ctrl.gray = 7;
- ctrl.xor = 7;
-
- if (MMI_Open(&ctrl) != NOERR){
- MMI_Close();
- return;
- }
- if (APL_init() != NOERR){
- MMI_Close();
- return;
- }
- MMI_ExecSystem();
- MMI_Close();
- }
-
- int aplid;
-
- APL_init()
- {
- extern int userFunc();
- extern int init();
- extern void setmode();
-
- aplid = MMI_GetApliId();
- init();
- setmode(TRUE);
- MMI_SendMessage(MMI_GetBaseObj(), MM_SETEXEC, 1, userFunc) ;
- MMI_CallMessage(aplid, GM_TITLE, (int)SERVER_TITLE, 0) ;
- MMI_CallMessage(aplid, GM_SLEEP, 0, 0) ;
- return NOERR ;
- }
-
- extern int create(), delete(), map(), unmap(), update(), move(), lower();
- static int (*winfuncs[])() = {
- create, delete, map, unmap, update, move, lower
- };
- struct list head = { NULL, NULL }, tail = { NULL, NULL };
-
- userFunc(int apliId, int messId, int info, int data)
- {
- int ret;
- extern void terminate(), setmode();
-
- ret = ILLEGAL_FUNCTION ;
-
- switch (messId){
- case GM_EXECUSER:
- if (info == 0)
- ret = MAGIC;
- else
- ret = (int)winfuncs;
- break;
- case GM_POSTSCRCHG:
- setmode(FALSE);
- ret = NOERR;
- break;
- case GM_QUIT:
- terminate();
- MMI_SetHaltFlag(TRUE);
- ret = NOERR;
- break;
- case GM_PURGE:
- case GM_ENVIRONMENT:
- case GM_SHOW:
- case GM_ERASE:
- case GM_UPDATE:
- ret = NOERR;
- break;
- }
- return (ret);
- }
-
- short vramseg;
- u_long vramoff;
- RESOLUTION mode = { 0, 0, 0, 0, 0, 0, };
- int own = FALSE;
- int fbxmax, pixelsize;
- void (*fbread)(), (*fbwrite)(), (*blkcpy)();
-
- void setmode(int init)
- {
- int owner;
- char *title;
- SCRNDATA screen;
- extern int modecmp();
- extern void setup();
-
- owner = MMI_CallMessage(aplid, GM_QUERYID, QM_BACKPAGE, 0);
- title = (char *)MMI_CallMessage(owner, GM_TITLE, (int)NULL, 0);
- #ifdef DEBUG
- printf("WIN: BACKPAGE owner is %s\n", title);
- #endif
- MMI_CallMessage(owner, GM_SCRNDATA, FALSE, (int)&screen);
- #ifdef DEBUG
- printf("WIN: setmode: %d %d %d %d %d %d 0x%x 0x%x\n", screen.usedPage,
- screen.page[1].vx, screen.page[1].vy,
- screen.page[1].dx, screen.page[1].dy,
- screen.page[1].pixel, screen.page[1].segment,
- screen.page[1].offset);
- #endif
- if (init){
- if (strcmp(title, OWNER) == 0){
- own = TRUE;
- mode = screen.page[1];
- setup(&screen.page[1]);
- } else {
- own = FALSE;
- }
- return;
- }
- if (own){
- if (strcmp(title, OWNER) == 0){
- if (modecmp(&mode, &screen.page[1]) != 0){
- #ifdef DEBUG
- printf("WIN: mode change\n");
- #endif
- mode = screen.page[1];
- setup(&screen.page[1]);
- }
- } else {
- own = FALSE;
- }
- } else {
- if (strcmp(title, OWNER) == 0){
- own = TRUE;
- setup(&mode);
- }
- }
- }
-
- void setup(RESOLUTION *page1)
- {
- struct window *p;
- extern void fbread16(), fbwrite16(), blkcpy16();
- extern void fbread4(), fbwrite4(), blkcpy4();
-
- #ifdef DEBUG
- printf("WIN: setup: %d %d %d %d %d 0x%x 0x%x\n",
- page1->vx, page1->vy, page1->dx, page1->dy, page1->pixel,
- page1->segment, page1->offset);
- #endif
- vramseg = page1->segment;
- vramoff = (u_long)page1->offset;
- fbxmax = page1->vx - 1;
- if (page1->pixel == 16){ /* 15bit color */
- fbread = fbread16;
- fbwrite = fbwrite16;
- blkcpy = blkcpy16;
- pixelsize = 2;
- } else if (page1->pixel == 4){ /* 4bit color */
- fbread = fbread4;
- fbwrite = fbwrite4;
- blkcpy = blkcpy4;
- pixelsize = 1;
- } else
- return;
- for (p=head.next; p->next != NULL; p=p->next)
- p->mapped = FALSE;
- }
-
- modecmp(RESOLUTION *a, RESOLUTION *b)
- {
- return (memcmp(a, b, sizeof (RESOLUTION) - sizeof (short)));
- }
-
- void terminate()
- {
- struct window *p;
-
- for (p = head.next; p->next != NULL; p = p->next)
- MMI_CallMessage(p->aplid, GM_EXECUSER, 0, 0);
- }
-